<?php

namespace app\common\model;

use app\common\model\BaseModel as BaseModel;
use ShidianUtil\Utils\NumberUtil;
use think\Collection;

/**
 * Class MemberInfo
 * @package app\model
 * @property int $memberId
 * @property int $activeLevels
 * @property string $realname
 * @property int $provinceId
 * @property int $cityId
 * @property string $practiceNumber
 * @property string $practicingLawFirm
 * @property string $certificatePic
 * @property int $practiceTime
 * @property string $indexPic
 * @property string $desc
 * @property string $introduce
 * @property string $lawFirmAdd
 * @property string $professionalField
 * @property string $chargingStandard
 * @property int $answerNumber
 * @property int $servedMemberNumber
 * @property int $commentMemberNumber
 * @property float $commentLevel
 * @property int $thanksNumber
 * @property int $attentions
 * @property int $msgOff
 * @property int $msgOpen
 * @property int $msgWay
 * @property int $askAvgTimes
 * @property int $medal
 * @property int $updated
 * @property int $created
 * @property string $certificatePicImg
 * @property string $indexPicImg
 * @property Collection $categories
 * @property Collection $ranks
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class MemberInfo extends BaseModel
{
    protected $name = 'MemberInfo';
    protected $pk = 'memberId';

    public function province()
    {
        return $this->hasOne(Area::class, 'id', 'provinceId');
    }

    public function city()
    {
        return $this->hasOne(Area::class, 'id', 'cityId');
    }

    // 擅长领域
    public function categories()
    {
        return $this->belongsToMany(LawCaseCategory::class, MemberCategoryRel::class, 'categoryId', 'memberId');
    }

    // 进入的榜单
    public function ranks()
    {
        return $this->hasMany(LawyerRank::class, 'lawyerId', 'memberId');
    }

    // 专业榜单
    public function professionalRank()
    {
        return $this->hasOne(LawyerRank::class, 'lawyerId', 'memberId');
    }

    // 好评榜单
    public function commentRank()
    {
        return $this->hasOne(LawyerRank::class, 'lawyerId', 'memberId');
    }

    // 律师的评价
    public function comments()
    {
        return $this->hasMany(ConsultingComment::class, 'lawyerId', 'memberId');
    }

    public function getCommentLevelAttr($value)
    {
        return number_format($value, 1, '.', '');
    }

    // 身份证图片
    public function getIdcardPicImgAttr($value, $data)
    {
        return image_url($data['idcardPic'] ?? '');
    }

    // 身份证图片2
    public function getIdcard2PicImgAttr($value, $data)
    {
        return image_url($data['idcard2Pic'] ?? '');
    }

    // 证书图片
    public function getCertificatePicImgAttr($value, $data)
    {
        return image_url($data['certificatePic'] ?? '');
    }

    public function getIndexPicImgAttr($value, $data)
    {
        return image_url($data['indexPic'] ?? '');
    }

    // 执业年限
    public function getPracticeTimeStrAttr($value, $data)
    {
        $now = time();
        $practiceTime = $data['practiceTime'] ?? $now;
        return date('Y', $now) - date('Y', $practiceTime) + 1;
    }


    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'MemberInfo表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'MemberInfo表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中MemberInfo的键');
    //    }
}
